package com.team.pulldown.controller;

import com.team.pulldown.model.XiaLaVo;
import com.team.pulldown.service.PullDownService;
import com.team.util.ResultBuildVo;
import com.team.util.ResultVo;
import com.team.util.StatusShengJIEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 李红历 on 2022/7/5.
 */
/*http://localhost:18082/swagger-ui.html#/*/
@RestController
@CrossOrigin//支持跨域
@Api(value="PullDownController" ,description="下拉框")
@RequestMapping("ware")//统一接口请求地址price
public class PullDownController {
    @Autowired
    private PullDownService pullDownService;
    @PostMapping("getPullDownList")//下拉框接口
    @ApiOperation(value="下拉框接口")
    public ResultVo queryPullDown(@RequestBody List<String> tmp){
        Map<String,List<XiaLaVo>> stringListMap = new HashMap<>();
        Map<String,List<XiaLaVo>> returnMap = new HashMap<>();
        //下拉查询启用禁用
        List<XiaLaVo> xiaLaVoList = new ArrayList<>();
        for (StatusShengJIEnum statusShengJIEnum: StatusShengJIEnum.values()){
            XiaLaVo xiaLaVo = new XiaLaVo(statusShengJIEnum.getId(), statusShengJIEnum.getName());
            xiaLaVoList.add(xiaLaVo);
        }
        stringListMap.put("status",xiaLaVoList);
        //法人下拉框
        List<XiaLaVo> personVoList = pullDownService.getPerson();
        stringListMap.put("person",personVoList);
        //库房编码下拉框
        List<XiaLaVo> wareVoList = pullDownService.getWare();
        stringListMap.put("ware",wareVoList);
        //库房标识下拉框
        List<XiaLaVo> signVoList = pullDownService.getSign();
        stringListMap.put("sign",signVoList);
        //库区编码下拉框
        List<XiaLaVo> areaVoList = pullDownService.getArea();
        stringListMap.put("area",areaVoList);
        //库区属性下拉
        List<XiaLaVo> propertyVoList = pullDownService.getProperty();
        stringListMap.put("property",propertyVoList);
        if (CollectionUtils.isEmpty(tmp)){
            return ResultBuildVo.success(stringListMap);
        }else {
            for (String qkey:tmp){
                for (String key:stringListMap.keySet()){
                    if (qkey.equals(key)){
                        returnMap.put(key,stringListMap.get(key));
                    }
                }
            }
            return ResultBuildVo.success(returnMap);
        }
    }
}
